﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using MvcApplication2.Ultilities;

namespace MvcApplication2.Providers
{
    public class ActiveDirectoryRoleProvider : RoleProvider
    {
        public override bool IsUserInRole(string username, string roleName)
        {
            var roles = GetRolesForUser(username);
            return Array.Exists(roles, s => s.Equals(roleName));
        }

        public override string[] GetRolesForUser(string username)
        {
            var roles = HttpContext.Current.Session[Constant.Roles];
            if (roles == null)
            {
                var userRoles = new string[2] {"Admin", Constant.ADGroup};
                HttpContext.Current.Session[Constant.Roles] = userRoles;

                return userRoles;
            }

            return (string[]) roles;
        }

        public override void AddUsersToRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }

        public override void CreateRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            throw new NotImplementedException();
        }

        public override string[] FindUsersInRole(string roleName, string usernameToMatch)
        {
            throw new NotImplementedException();
        }

        public override string[] GetAllRoles()
        {
            throw new NotImplementedException();
        }

        public override string[] GetUsersInRole(string roleName)
        {
            throw new NotImplementedException();
        }

        public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
        {
            throw new NotImplementedException();
        }

        public override bool RoleExists(string roleName)
        {
            throw new NotImplementedException();
        }
    }
}